1 /*** 2 * Redistribution and use in source and binary forms, with or without 3 * modification, are permitted provided that the following conditions are 4 * met : 5 * 6 * . Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * 9 * . Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * . The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id$ 29 */ 30 31 package palmed.edit.text; 32 33 import java.io.IOException; 34 import java.io.InputStream; 35 import java.io.OutputStream; 36 import palmed.edit.util.Coordinate; 37 38 /*** 39 * This interface defines a chunk of text. 40 * 41 * @author Mathieu Champlon 42 * @version $Revision$ $Date$ 43 */ 44 interface IChunk extends ICachable 45 { 46 /*** 47 * Retrieve the height of this chunk. 48 * <p> 49 * It slightly differs from the height of the underlying text as the first line is considered as part of the 50 * previous chunk and therefore is not counted. 51 * <p> 52 * Actually returns the height of the underlying text - 1. 53 * 54 * @return the height of the chunk 55 */ 56 int getHeight(); 57 58 /*** 59 * Test the modification flag. 60 * 61 * @return whether the text has been modified since it has been read or written 62 */ 63 boolean hasBeenModified(); 64 65 /*** 66 * Call a functor if the given line number is inside the chunk. 67 * 68 * @param functor the functor 69 * @param line the absolute line number 70 * @return the possibly updated by the functor number of lines in the chunk 71 */ 72 int handle( ILineExtractor functor, int line ); 73 74 /*** 75 * Call a functor if the area defined by given coordinates intersects the chunk. 76 * 77 * @param functor the functor 78 * @param start the absolute starting position of this chunk 79 * @param from the absolute coordinate of the beginning of the area 80 * @param to the absolute coordinate of the end of the area 81 * @return the absolute ending position of this chunk 82 */ 83 Coordinate handle( ITextExtractor functor, Coordinate start, Coordinate from, Coordinate to ); 84 85 /*** 86 * Count the number of columns and lines. 87 * 88 * @param size the size to increment 89 * @param previous the length of the last line of the previous chunk 90 * @return the length of the last line of this chunk 91 */ 92 int count( Coordinate size, int previous ); 93 94 void read( InputStream stream ) throws IOException; 95 96 void write( OutputStream stream ) throws IOException; 97 }